<template>
  <div>
    <el-form :inline="true" ref="queryForm" :model="query">
      <el-row type="flex" class="row-bg" justify="space-between">
        <el-col :span="18">
          <!-- 检索条件 start -->
          <el-form-item label="姓名" prop="nickname">
            <el-input
              v-model="query.nickname"
              placeholder="请输入昵称"
            ></el-input>
          </el-form-item>
          <!-- 检索条件 end -->

          <el-form-item>
            <el-button icon="el-icon-search" @click="querySearchForm"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" @click="resetSearchForm"
              >重置</el-button
            >
          </el-form-item>
        </el-col>

        <el-col :span="6" class="table-tools">
          <el-button
            @click="openDialog()"
            icon="el-icon-plus"
            v-if="hasPermission(permission.save)"
            >{{ "添加" + dialogTitle }}</el-button
          >
        </el-col>
      </el-row>
    </el-form>

    <el-table
      stripe
      border
      :data="tableData"
      style="width: 100%"
      :height="maxTableHeight"
    >
      <!-- 表格属性 start -->
      <el-table-column prop="nickname" label="姓名" width="180">
      </el-table-column>
      <el-table-column prop="account" label="账号"> </el-table-column>
      <el-table-column prop="lastLoginTime" label="上次登录时间">
        <template slot-scope="{ row }">
          {{ row.lastLoginTime || "----" }}
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="创建时间"> </el-table-column>
      <!-- 表格属性 end -->

      <el-table-column
        fixed="right"
        label="操作"
        width="100"
        v-if="hasAnyPermission()"
      >
        <template slot-scope="scope">
          <el-button
            type="text"
            size="medium"
            icon="el-icon-edit"
            @click="openDialog(scope.row)"
            v-if="hasPermission(permission.update)"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageInfo.page"
      :page-sizes="[10, 20, 50]"
      :page-size="pageInfo.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageInfo.total"
    >
    </el-pagination>

    <Update ref="updateDialog" :dialogTitle="dialogTitle"></Update>
  </div> 
</template>

<script>
import { mapState } from "vuex";
import listMixins from "@/views/base/listMixins";

// 请求接口 start
import Update from "@/views/sys/user/update";
import sysApi from "@/api/sysApi";
// 请求接口 end

export default {
  // 组件名称 start
  name: "sysUser",
  // 组件名称 start

  components: {
    Update,
  },
  mixins: [listMixins],
  data() {
    return {
      // 数据 start
      dialogTitle: "用户",
      permission: {
        save: "sys:user:save",
        update: "sys:user:update",
      },
      query: {
        nickname: "",
        account: "",
      },
      // 数据 end
    };
  },
  methods: {
    remoteTableData() {
      // 分页请求 start
      sysApi.sysUser.listPage(this.searchParams()).then((res) => {
        this.updateTableData(res.data);
      });
      // 分页请求 end
    },
  },
  computed: mapState({
    user: (state) => state.user.userInfo,
  }),
};
</script>